<?php

// Namespace

namespace Loop;


/**
 * CConstantManager is a class that takes care of defining constants
 */

class CConstantManager
{
	/**
	 * Initializes constants defined in the application
	 */
	
	public function initialize()
	{
		// Get paths of extensions + application
		
		$pathsToExtensions = app()->getExtensionManager()->getPathsToExtensions();
		
		
		// Now render application constants
		
		foreach ($pathsToExtensions as $pathToExtension)
		{

			$pathsToFiles = app()->getFileHelper()->listFiles($pathToExtension . 'Constant/', '*.php');

			
			foreach ($pathsToFiles as $pathToFile)
			{

				// Render
				
				require_once($pathToFile);
			}
			
		}
	}
	
	
	/**
	 * Defines a constant
	 *
	 * @param	string	$constantName	The name of the constant
	 * @param	string	$constantValue	The value of the constant (can be null)
	 */
	
	public function setConstant($constantName, $constantValue = null)
	{
		// Has the constant already been defined?
		
		if (defined($constantName) == false)
		{
			// No, so let's define the constant
				
			if (empty($constantValue) == true)
			{
				// No value given, use the constant name for the value
				
				define($constantName, $constantName);
			}
			else
			{
				define($constantName, $constantValue);
			}
		}
	}


	/**
	 * Get a constant
	 *
	 * @param	string	$constantName	The name of the constant
	 *
	 * @return 	mixed 	The defined constant 	
	 */
	
	public function getConstant($constantName)
	{
		// Has the constant already been defined?
		
		if (defined($constantName) == true)
		{
			// Yes

			return constant($constantName);
		}
	}	
}

?>
